package com.voltmao.service.application.sys;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.voltmao.persistent.mapper.SysDictionaryMapper;
import com.voltmao.persistent.model.SysDictionary;
import com.voltmao.persistent.model.SysDictionaryCriteria;

import java.util.List;

/**
 * 字典管理服务接口
 *
 * @author zhanglin
 * @date 2018/04/12
 */
@Service
public class DictionaryServiceImpl {
    private static final Logger mainLogger = LoggerFactory.getLogger(DictionaryServiceImpl.class);
    private static final Logger testLogger = LoggerFactory.getLogger("MY_TEST_LOGGER");
    @Autowired
    SysDictionaryMapper sysDictionaryMapper;

    /**
     * 根据pcode来查询所属的所有记录
     *
     * @param pcode 父节点
     * @return 当前父节点下所有记录
     */
    public List<SysDictionary> getDictionaryByPCode(String pcode){
        testLogger.info("字典查询字段：pcode="+pcode);
        SysDictionaryCriteria example = new SysDictionaryCriteria();
        SysDictionaryCriteria.Criteria c = example.createCriteria();
        c.andPcodeEqualTo(pcode);
        return sysDictionaryMapper.selectByExample(example);
    }

    /**
     * 根据code和pcode来查询一条记录
     * @param code 当前子节点
     * @param pcode 父节点
     * @return 一条字典记录
     */
    public SysDictionary getDictionaryByCodeAndPcode(String code, String pcode){
        testLogger.info("字典查询字段：pcode="+pcode+";   code="+code);
        SysDictionaryCriteria example = new SysDictionaryCriteria();
        SysDictionaryCriteria.Criteria c = example.createCriteria();
        c.andCodeEqualTo(code);
        c.andPcodeEqualTo(pcode);
        return sysDictionaryMapper.selectByExampleForOne(example);
    }
}
